#include <iostream>
using namespace std;
#include <deque>

const int N = 5e5 + 5;
int a[N];
int n, k;
deque<int> q;

void m_queue()
{
	int left = 0, right = 0;
	while (right < n)
	{
		int cur = a[right++];
		while (!q.empty() && cur > q.back())
		{
			q.pop_back();
		}
		q.push_back(cur);
		
		if (q.size() > k)
			q.pop_front();
			
		if (right - left == k)
		{
			cout << q.front() << " ";
			left++;
		}
	}
}
int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	m_queue();
	return 0;
}

/*
8 3
1 3 -1 -3 5 3 6 7
*/